#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> findSmallestSetOfVertices(int n, vector<vector<int>>& edges) {
        vector<int>book = vector<int>(n,0);
        vector<int>ans = {};
        for(int i=0;i<edges.size();i++){
            int index = edges[i][1];
            book[index] = 1;    //标记存在入度的点
        }
        for(int i=0;i<n;i++){
            if(book[i]==0)  //找到入度为0的节点
                ans.push_back(i);
        }
        return ans;
    }
};
int main(int argc, char* argv[]){
    Solution *s = new Solution();
    vector<vector<int>> edges = {{0,1},{0,2},{2,5},{3,4},{4,2}};
    vector<int>ans = s->findSmallestSetOfVertices(6, edges);
    for(int n:ans)
        cout<<n<<" "<<endl;
    return 0;
}